import 'package:uuid/uuid.dart';

class Baby {
  final String id;
  final String name;
  final String gender;
  final DateTime birthDate;
  final String? avatarUrl;
  final bool isDefault; // Added isDefault property

  const Baby({
    required this.id,
    required this.name,
    required this.gender,
    required this.birthDate,
    this.avatarUrl,
    this.isDefault = false, // Default value is false
  });

  // Convert Baby instance to a Map
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'gender': gender,
      'birthDate': birthDate.toIso8601String(),
      'avatarUrl': avatarUrl,
      'isDefault': isDefault ? 1 : 0, // Store as integer in database
    };
  }

  // Create a Baby instance from a Map
  factory Baby.fromMap(Map<String, dynamic> map) {
    return Baby(
      id: map['id'] as String,
      name: map['name'] as String,
      gender: map['gender'] as String,
      birthDate: DateTime.parse(map['birthDate'] as String),
      avatarUrl: map['avatarUrl'] as String?,
      isDefault: (map['isDefault'] as int) == 1, // Convert integer to boolean
    );
  }

  // Create a copy of Baby with some fields replaced
  Baby copyWith({
    String? id,
    String? name,
    String? gender,
    DateTime? birthDate,
    String? avatarUrl,
    bool? isDefault,
  }) {
    return Baby(
      id: id ?? this.id,
      name: name ?? this.name,
      gender: gender ?? this.gender,
      birthDate: birthDate ?? this.birthDate,
      avatarUrl: avatarUrl ?? this.avatarUrl,
      isDefault: isDefault ?? this.isDefault,
    );
  }
}
